@extends('admin.layout')
@section('content')
<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品管理
                <small>在这里,你可以编辑商品
                    @if(session('info'))
                    <span id='info' class="text-red"> {{session('info')}}</span>
                    @endif
                </small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{ url('/admin/index') }}"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="{{ url('/admin/') }}">商品管理</a></li>
                <li class="active">添加</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">编辑商品</h3>
                        </div><!-- /.box-header -->
                        
                        <!-- form start --> 
                        <form role="form" action="{{ url('/admin/goods/update') }}" method="post" enctype="multipart/form-data">
                        {{csrf_field()}}
                            <div class="box-body">

                            @if (count($errors) > 0)
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif
                            <input type="hidden" name="gid" value="{{ $data_goods -> gid }}">
                                <div class="form-group">
                                    <label for="exampleInputEmail1">商品名称</label>
                                    <input type="text" value="@if(!empty(old('goodsname'))){{ old('goodsname') }}@else{{$data_goods -> goodsname}}@endif" class="form-control" name="goodsname" id="exampleInputEmail1"
                                           placeholder="请输入商品名称">
                                </div>
                                <div class="form-group">
                                    <label>父分类</label>
                                    <select class="form-control" name="tid">
                                    @foreach($data_category as $row)
                                        <option 
                                        @if($data_goods -> tid == $row -> id)
                                        selected="selected"
                                        @endif

                                        @if($data_goods -> tid == $row -> id)
                                        disabled = "disabled"
                                        @endif


                                        value="{{$row -> id}}">{{$row -> name}}
                                        </option>
                                    @endforeach
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品价格</label>
                                    <input type="text" value="@if(!empty(old('price'))){{ old('price') }}@else{{$data_goods -> price}}@endif"class="form-control" name="price" id="exampleInputPassword1"
                                           placeholder="请输入价格">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品库存</label>
                                    <input type="text" value="@if(!empty(old('store'))){{ old('store') }}@else{{$data_goods -> store}}@endif" class="form-control" name="store" id="exampleInputPassword1"
                                           placeholder="请输入商品库存">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品简介</label>
                                    <textarea name="desc" class="form-control" id="exampleInputEmail1" cols="174" rows="5"
                                     placeholder="请输入商品简介">@if(!empty(old('desc'))){{ old('desc') }}@else{{$data_goods -> desc}}@endif</textarea>
                                </div>
                                <div class="form-group">
                                    <input name="status" size="50" @if($data_goods -> status == 1 )checked @endif value="1" type="radio">新品
                                    <input name="status" size="50" @if($data_goods -> status == 2 )checked @endif value="2" type="radio">在售
                                    <input name="status" size="50" @if($data_goods -> status == 2 )checked @endif value="0" type="radio">下架
                                </td>
                                </div>
                                <div class="form-group">

                                    <label for="exampleInputFile">商品图片</label>
                                    <input type="file" name="goodspic" id="exampleInputFile">
                                    <p class="help-block">请选择一张你的图片,作为商品图片.</p>
                                    <p><img width="100px;" src="@if(!empty(old('goodspic'))){{ asset(old('goodspic')) }}@else{{asset($data_goods -> goodspic)}}@endif"></p>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputFile">详情大图</label>
                                    <input type="file" name="goodspic_max" id="exampleInputFile">
                                    <p class="help-block">请选择一张你的图片,作为详情大图.</p>
                                    <p><img width="100px;" src="{{ asset($data_goods -> goodspic_max) }}" value=""></p>
                                    <!-- <p><img width="100px;" src="{{ $data_goods -> goodspic_max }}"></p> -->
                                </div>
                                
                            </div><!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">更新</button>
                            </div>
                        </form>
                    </div><!-- /.box -->

                    

                    
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->

                </div><!--/.col (left) -->
                
            </div>   <!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script type="text/javascript">
    window.onload = function(){
        $('#info').fadeOut(1000);
    }
    </script>
@endsection